home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / gamesmaster / source / asm / screendemos / widescroll&sprite.s < prev   
Encoding:
Text File  |  1996-09-12  |  6.3 KB  |  231 lines

  1. ;Wide Scroll & Sprite
  2. ;--------------------
  3. ;This opens an extra wide picture of 640x256 pixels and sticks an animated
  4. ;sprite on top of it.  Extremely large pictures are *totally* inadequate for
  5. ;games such as platformers and shoot'em-ups, because the picture size takes
  6. ;up  huge  amounts  of  memory.   However  for games like Skidmarks,
  7. ;Lemmings, Monkey Island, etc, such large screens can be a necessity.
  8. ;
  9. ;Moving the sprite to the edges of the screen will result in a sound.
  10. ;
  11. ;Press LMB to exit.
  12.  
  13.     opt    o+
  14.  
  15.     INCLUDE    "exec/exec_lib.i"
  16.     INCLUDE    "games/games_lib.i"
  17.     INCLUDE    "games/games.i"
  18.  
  19. CALL    MACRO
  20.     jsr    _LVO\1(a6)
  21.     ENDM
  22.  
  23.     SECTION    "WideScroll&Sprite",CODE
  24.  
  25. ;===========================================================================;
  26. ;                             INITIALISE DEMO
  27. ;===========================================================================;
  28.  
  29. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  30.     move.l    ($4).w,a6
  31.     lea    GMS_Name(pc),a1
  32.     moveq    #$00,d0
  33.     CALL    OpenLibrary
  34.     move.l    d0,GMS_Base
  35.     beq    Quit
  36.  
  37.     move.l    GMS_Base(pc),a6          ;Set task at the user-specified
  38.     CALL    SetUserPri               ;priority.
  39.  
  40.     CALL    AllocAudio
  41.     tst.w    d0
  42.     bne    DeleteScr
  43.  
  44.     lea    Sound_Gong(pc),a0
  45.     CALL    InitSound
  46.     tst.w    d0
  47.     bne    ReturnToDOS
  48.  
  49.     lea    ScreenStruct(pc),a0
  50.     CALL    Add_Screen
  51.     tst.l    d0
  52.     bne    Error
  53.  
  54.     lea    Picture(pc),a1           ;a1 = Picture struct.
  55.     move.l    SS_MemPtr1(a0),PIC_Data(a1)
  56.     lea    PicFile(pc),a0           ;a0 = Picture file.
  57.     CALL    LoadPic
  58.     tst.w    d0
  59.     bne    ReturnToDOS
  60.  
  61.     lea    ScreenStruct(pc),a0
  62.     lea    SparkieStruct(pc),a1
  63.     CALL    Init_Sprite
  64.     CALL    Update_Sprite            ;First get him onto the screen.
  65.  
  66.     CALL    Show_Screen
  67.  
  68.     moveq    #JPORT1,d0               ;Initialise the mouse port.
  69.     CALL    Read_Mouse
  70.  
  71. ;===========================================================================;
  72. ;                                MAIN LOOP
  73. ;===========================================================================;
  74.  
  75.     moveq    #$00,d6                  ;d6 = 00.
  76. Loop:    moveq    #JPORT1,d0               ;Read from port 1
  77.     CALL    Read_Mouse               ;Go get mouse movements.
  78.     move.w    d0,d1
  79.     asr.w    #8,d0
  80.     add.w    d0,SPR_XPos(a1)
  81.     ext.w    d1
  82.     add.w    d1,SPR_YPos(a1)
  83.     btst    #MB_LMB,d0
  84.     bne.s    ReturnToDOS
  85.  
  86.     addq.w    #1,d7                    ;Animation/Frame delay, so that
  87.     btst    #0,d7                    ; our anim does not run too fast!
  88.     beq.s    Scroller
  89.     cmp.w    #5,SPR_Frame(a1)         ;Do the animation for the sprite.
  90.     beq.s    .reset                   ;(simply by increasing the frame
  91.     addq.w    #1,SPR_Frame(a1)         ; number).
  92.     bra.s    Scroller
  93. .reset    clr.w    SPR_Frame(a1)
  94.  
  95. Scroller:
  96.     lea    ScreenStruct(pc),a0
  97.     tst.w    d6
  98.     beq.s    .Right
  99. .Left    tst.w    SS_PicXOffset(a0)
  100.     ble.s    .Right
  101.     st    d6
  102.     subq.w    #2,SS_PicXOffset(a0)
  103.     bra.s    .scroll
  104. .Right    cmp.w    #320,SS_PicXOffset(a0)
  105.     bge.s    .Left
  106.     moveq    #$00,d6
  107.     addq.w    #2,SS_PicXOffset(a0)
  108.  
  109. .scroll    CALL    Move_Picture
  110.     CALL    Wait_OSVBL
  111.     CALL    Update_Sprite            ;Put Sparkie on the screen.
  112.  
  113.     cmp.w    #320-16,SPR_XPos(a1)
  114.     bge.s    .play
  115.     tst.w    SPR_XPos(a1)
  116.     ble.s    .play
  117.     tst.w    SPR_YPos(a1)
  118.     ble.s    .play
  119.     cmp.w    #256-16,SPR_YPos(a1)
  120.     bge.s    .play
  121.     bra    Loop
  122.  
  123. .play    lea    Sound_Gong(pc),a0
  124.     CALL    PlaySoundPri
  125.     bra    Loop
  126.  
  127. ;===========================================================================;
  128. ;                              RETURN TO DOS
  129. ;===========================================================================;
  130.  
  131. ReturnToDOS:
  132.     move.l    GMS_Base(pc),a6
  133.     lea    Sound_Gong(pc),a0
  134.     CALL    FreeSound
  135.     CALL    FreeAudio
  136. DeleteScr:
  137.     move.l    GMS_Base(pc),a6
  138.     lea    ScreenStruct(pc),a0
  139.     CALL    Delete_Screen            ;Give back screen memory etc.
  140. Error:    move.l    GMS_Base(pc),a1
  141.     move.l    ($4).w,a6
  142.     CALL    CloseLibrary
  143. Quit:    MOVEM.L    (SP)+,A0-A6/D1-D7
  144.     moveq    #$00,d0
  145.     rts
  146.  
  147. ;===========================================================================;
  148. ;                                  DATA
  149. ;===========================================================================;
  150.  
  151. GMS_Name:
  152.     dc.b    "games.library",0
  153.     even
  154. GMS_Base:
  155.     dc.l    0
  156.  
  157. AMT_PLANES =    4
  158.  
  159. SparkieStruct:
  160.     dc.l    "SPV1",0          ;Structure version.
  161.     dc.w    0                 ;Number 0.
  162.     dc.l    Gfx_Sparkie       ;Ptr to graphic.
  163.     dc.w    150,150           ;Beginning X/Y position
  164.     dc.w    0                 ;Current frame.
  165.     dc.w    16,21             ;Width (16/32/64), Height.
  166.     dc.w    16                ;Amt of colours.
  167.     dc.w    16                ;Colour start in palette.
  168.     dc.w    2                 ;Amt of planes.
  169.     dc.w    HIRES|XLONG       ;Attributes.
  170.     dc.w    0                 ;PlayField position.
  171.     dc.l    0,0               ;Private.
  172.  
  173. ScreenStruct:
  174.     dc.l    "GSV1",0
  175.     dc.l    0,0,0             ;Screen_Mem1/2/3
  176.     dc.l    0                 ;Screen link.
  177.     dc.l    Palette           ;Address of palette
  178.     dc.l    0                 ;Address of rasterlist.
  179.     dc.l    32                ;Amt of colours in palette.
  180.     dc.w    320,256,640,256   ;Screen & Pic Height/Width. 
  181.     dc.w    AMT_PLANES        ;Amt_Planes
  182.     dc.w    0,0               ;X/Y screen offset.
  183.     dc.w    0,0               ;X/Y picture offset.
  184.     dc.l    HSCROLL           ;Special attributes.
  185.     dc.w    LORES             ;Screen mode.
  186.     dc.b    INTERLEAVED       ;Screen type
  187.     dc.b    0                 ;Reserved.
  188.     even
  189.  
  190. Palette    dc.w    $0000,$0400,$0501,$0501,$0601,$0701,$0701,$0801
  191.     dc.w    $0901,$0A01,$0B02,$0432,$0CC0,$0F00,$0211,$0880
  192.     dc.w    $01C2,$0050,$0B0B,$0606,$0F20,$0910,$0BBB,$0FFF
  193.     dc.w    $00BF,$0068,$0568,$09BF,$0FF0,$0EE0,$0BA0,$0540
  194.  
  195. PicFile    dc.b    "GAMESLIB:data/IFF.Pic640x256",0
  196.     even
  197.  
  198. Picture    dc.l    "PCV1",0           ;Version header.
  199.     dc.l    0                  ;Source data.
  200.     dc.w    640,256            ;Width, Height.
  201.     dc.w    AMT_PLANES         ;Amount of Planes.
  202.     dc.l    32                 ;Amount of colours.
  203.     dc.l    Palette            ;Source palette (remap).
  204.     dc.w    LORES              ;Screen mode.
  205.     dc.w    INTERLEAVED        ;Destination
  206.     dc.l    0                  ;Parameters.
  207.  
  208. Sound_Gong:
  209.     dc.l    "SMV1",0           ;Structure version.
  210.     dc.w    CHANNEL1           ;Channel to play through.
  211.     dc.w    0                  ;Priority.
  212.     dc.l    0                  ;Sample header
  213.     dc.l    0                  ;Sample address.
  214.     dc.l    0                  ;Sample length.
  215.     dc.w    OCT_C2             ;Sample period.
  216.     dc.w    100                ;Sample volume.
  217.     dc.l    SBIT8|SEMPTY       ;Sound is 8 bit.
  218.     dc.l    Gong               ;Sound file.
  219.  
  220. Gong:    dc.b    "GAMESLIB:data/IFF.Lightning",0
  221.     even
  222.  
  223. ;===========================================================================;
  224. ;                              CHIP RAM DATA
  225. ;===========================================================================;
  226.  
  227.     SECTION    "Graphics",DATA_C
  228.  
  229. Gfx_Sparkie:
  230.     INCBIN    "GAMESLIB:data/Sparkie.raw"
  231.